//
//  UserDataBase.m
//  哎游
//
//  Created by 康守帅 on 15-1-14.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "UserDataBase.h"
#import "DB.h"

@implementation UserDataBase

+ (void)insertIntoUserName:(NSString *)userName passWord:(NSString *)passWord
{
    sqlite3 *dbPoint = [DB openDB];
    NSString *sqlStr = [NSString stringWithFormat:@"insert into local(user_name, user_password) values ('%@', '%@')", userName, passWord];
    
    int result = sqlite3_exec(dbPoint, [sqlStr UTF8String], nil, nil, nil);
    if (result == SQLITE_OK) {
        NSLog(@"插入成功");
    }else {
        NSLog(@"插入失败");
    }
}

+ (BOOL)selectForUserName:(NSString *)userName
{
    BOOL exist = NO;
    sqlite3 *dbPoint = [DB openDB];
    sqlite3_stmt *stmt = nil;
    NSString *sqlStr = [NSString stringWithFormat:@"select * from local where user_name = '%@'", userName];
    int result = sqlite3_prepare_v2(dbPoint, [sqlStr UTF8String], -1, &stmt, nil);
    if (result == SQLITE_OK) {
        if (sqlite3_step(stmt) == SQLITE_ROW) {
            exist = YES;
        }
    }
    sqlite3_finalize(stmt);
    return exist;
}

+ (BOOL)selectForUserName:(NSString *)userName passWord:(NSString *)passWord
{
    BOOL exist = NO;
    sqlite3 *dbPoint = [DB openDB];
    sqlite3_stmt *stmt = nil;
    NSString *sqlStr = [NSString stringWithFormat:@"select * from local where user_name = '%@' and user_password = '%@'", userName, passWord];
    int result = sqlite3_prepare_v2(dbPoint, [sqlStr UTF8String], -1, &stmt, nil);
    if (result == SQLITE_OK) {
        if (sqlite3_step(stmt) == SQLITE_ROW) {
            exist = YES;
        }
    }
    sqlite3_finalize(stmt);
    return exist;
}






@end
